# #Lagos download script
LAGOSNE::lagosne_get(dest_folder = LAGOSNE:::lagos_path())
## Warning in LAGOSNE::lagosne_get(dest_folder = LAGOSNE:::lagos_path()): LAGOSNE data for this version already exists on the local machine.
## Re-download if neccessary using the 'overwrite` argument.'
#Load in lagos
lagos <- lagosne_load()
## Warning in (function (version = NULL, fpath = NA) : LAGOSNE version unspecified,
## loading version: 1.087.3
#Grab the lake centroid info
lake_centers <- lagos$locus
#Look at the column names
#names(lake_centers)
#Look at the structure
#str(lake_centers)
#View the full dataset
#View(lake_centers %>% slice(1:100))
spatial_lakes <- st_as_sf(lake_centers,coords=c('nhd_long','nhd_lat'),
crs=4326) %>%
st_transform(2163)
#Subset for plotting
subset_spatial <- spatial_lakes %>%
slice(1:100)
subset_baser <- spatial_lakes[1:100,]
#Dynamic mapviewer
mapview(subset_spatial)
states <- us_states()
#Plot all the states to check if they loaded
mapview(states)
minnesota <- states %>%
filter(name == 'Minnesota') %>%
st_transform(2163)
#Subset lakes based on spatial position
minnesota_lakes <- spatial_lakes[minnesota,]
#Plotting the first 1000 lakes
minnesota_lakes %>%
arrange(-lake_area_ha) %>%
slice(1:1000) %>%
mapview(.,zcol = 'lake_area_ha')
the_ayes <- states %>%
filter(name %in% c('Iowa','Illinois')) %>%
st_transform(2163)
mapview(the_ayes, color = 'violet', alpha.regions = 0)
combined? How does this compare to Minnesota?
#Subset lakes based on spatial position
il_ia_lakes <- spatial_lakes[the_ayes,]
#How many sites are in the il_ia dataset?
print(paste('There are', length(il_ia_lakes$lagoslakeid), 'sites in Illinois and Iowa combined'))
## [1] "There are 16466 sites in Illinois and Iowa combined"
print(paste('There are', length(minnesota_lakes$lagoslakeid), 'sites in Minnesota'))
## [1] "There are 29038 sites in Minnesota"
Response:
There are about half as many sites in Iowa and Illinois combined compared to Minnesota
# subset Iowa lakes
ia<- states %>%
filter(name %in% c('Iowa')) %>%
st_transform(2163)
iowa_lakes <- spatial_lakes[ia,]
# subset both dataframes to desired columns, include state name as a column
minn_lakes <- minnesota_lakes %>%
select(c(lagoslakeid, gnis_name, lake_area_ha))
minn_lakes$state <- 'Minnesota'
ia_lakes <- iowa_lakes %>%
select(c(lagoslakeid, gnis_name, lake_area_ha))
ia_lakes$state <- 'Iowa'
# rbind the two dataframes
plotthis <- rbind(minn_lakes, ia_lakes)
# generate histograms with a 'state' facet wrap, but transform lake area
ggplot(plotthis, aes(lake_area_ha)) +
geom_histogram() +
facet_wrap(as.factor(plotthis$state)) +
scale_x_continuous("Lake area (ha)", labels = comma, trans = "log10") +
ylab('Number of lakes')
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
by lake area in hectares
# using same code as above except with an Iowa and Illinois subset. Arrange sot that more rare (larger) lake sizes are plotted last and therefore more visible.
il_ia_lakes %>%
arrange(lake_area_ha) %>%
mapview(.,zcol = 'lake_area_ha')